<template>
  <div class="my-counter">
    <button type="button" class="btn btn-light" @click="decrement">-</button>
    <input type="number" class="form-control inp" :value="value" />
    <button type="button" class="btn btn-light" @click="increment">+</button>
  </div>
</template>

<script>
export default {
  props: {
    value: Number,
  },

  methods:{
    //点击加号，让父组件数字加1
    increment(){
      this.$emit('input',this.value+1)
    },
    //点击加号，让父组件数字减1
    decrement(){
      this.$emit('input',this.value-1)
    }
  }
}
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 45px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>
